import { ref } from 'vue'
import { AddOrderChildTypeForm } from './types'
import { moduleTypeSave } from '@/api/basic'

export default () => {
  const addOrderChildTypeLoading = ref(false)

  const addOrderChildTypeForm = ref<AddOrderChildTypeForm>({
    id: '',
    name: '',
    parentId: '',
    status: false,
    childData: [],
  })

  const resetAddOrderChildTypeForm = () => {
    addOrderChildTypeForm.value = {
      id: '',
      name: '',
      parentId: '',
      status: false,
      childData: [],
    }
  }

  const addOrderChildType = async (orderModuleId: string) => {
    addOrderChildTypeLoading.value = true
    const res = await moduleTypeSave(addOrderChildTypeForm.value, orderModuleId)
    addOrderChildTypeLoading.value = false
    return res.data as { code: number; message: string; success: boolean; data: object }
  }

  return {
    addOrderChildTypeForm,
    addOrderChildTypeLoading,
    addOrderChildType,
    resetAddOrderChildTypeForm,
  }
}
